package com.minimalist.common.feign.fallback.tc;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.tc.entity.vo.plateNumber.TcPlateNumberQueryVO;
import com.minimalist.common.entity.tc.entity.vo.plateNumber.TcPlateNumberVO;
import com.minimalist.common.feign.client.tc.TcPlateNumberFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 车牌号管理 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class TcPlateNumberFeignClientFallbackFactory extends BaseFallbackFactory<TcPlateNumberFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(TcPlateNumberFeignClientFallbackFactory.class);


    @Override
    public TcPlateNumberFeignClient create(Throwable cause) {
        return new TcPlateNumberFeignClient() {
            @Override
            public ResponseEntity<Void> addPlateNumber(TcPlateNumberVO plateNumberVO) {
                logServiceUnavailable("添加车牌号", plateNumberVO, cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }

            @Override
            public ResponseEntity<Void> batchAddPlateNumber(List<TcPlateNumberVO> plateNumberVOList) {
                logServiceUnavailable("批量添加车牌号", plateNumberVOList.size(), cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }

            @Override
            public ResponseEntity<Void> updatePlateNumber(TcPlateNumberVO plateNumberVO) {
                logServiceUnavailable("更新车牌号", plateNumberVO, cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }

            @Override
            public ResponseEntity<Void> deletePlateNumber(Long plateNumberId) {
                logServiceUnavailable("删除车牌号", plateNumberId, cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }

            @Override
            public ResponseEntity<TcPlateNumberVO> getPlateNumber(Long plateNumberId) {
                logServiceUnavailable("获取车牌号详情", plateNumberId, cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }

            @Override
            public ResponseEntity<PageResp<TcPlateNumberVO>> getPagePlateNumberList(TcPlateNumberQueryVO queryVO) {
                logServiceUnavailable("分页查询车牌号列表", queryVO, cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body(new PageResp<>(List.of(), 0));
            }

            @Override
            public ResponseEntity<String> recognizePlateNumber(String imageBase64) {
                logServiceUnavailable("识别车牌号", "图片数据", cause);
                return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
            }
        };
    }
}
